Read and preprocess control-data

if (!require("pacman")) install.packages("pacman")
library(pacman)
p_load(tidyverse)
p_load(R.utils)
sourceDirectory("./source/")
data<-readControl()  %>% preproControl() 

check accuracy

corrResp: correct response rtResp: reaction time of response - inSet: 0 - correct rejection (true negativ) - inSet: 1 - Hit (true positiv) - session: 1-5 - time factor (not constant, therefore only ordinal) - kategory: Landscape, Face, Art

p_load(dplyr)
p_load(brms)
options (mc.cores=parallel::detectCores ()) # Run on multiple cores
p_load(sjPlot)


group_by(data,kategory,session) %>% 
  summarize(mean_corr= mean(corrResp),sd_corr=sd(corrResp),mean_RT=mean(rtResp),sd_RT=sd(rtResp))
p <- ggplot(data=data, 
             aes(x = corrResp, y =rtResp, color= inSet) )+geom_point()
p+facet_grid(kategory  ~  session,margins = T)

p+facet_grid(kategory ~ participant)

#correct response 
fit_corrRespSessionPart<-lm(corrResp~participant*session,data = data)
summary(fit_corrRespSessionPart)
## 
## Call:
## lm(formula = corrResp ~ participant * session, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.7667 -0.5667  0.3333  0.4000  0.5000 
## 
## Coefficients: (7 not defined because of singularities)
##                            Estimate Std. Error t value Pr(>|t|)    
## (Intercept)               6.000e-01  8.994e-02   6.671 6.48e-11 ***
## participantha94          -5.432e-15  1.272e-01   0.000    1.000    
## participantma92          -6.667e-02  1.272e-01  -0.524    0.600    
## participantod94           3.333e-02  1.272e-01   0.262    0.793    
## participantug93           6.667e-02  1.272e-01   0.524    0.600    
## session2                  2.925e-15  1.272e-01   0.000    1.000    
## session3                  3.333e-02  1.272e-01   0.262    0.793    
## session4                 -6.667e-02  1.272e-01  -0.524    0.600    
## session5                 -6.667e-02  1.272e-01  -0.524    0.600    
## participantha94:session2 -3.333e-02  1.799e-01  -0.185    0.853    
## participantma92:session2  2.333e-01  1.799e-01   1.297    0.195    
## participantod94:session2 -1.333e-01  1.799e-01  -0.741    0.459    
## participantug93:session2         NA         NA      NA       NA    
## participantha94:session3 -3.333e-02  1.799e-01  -0.185    0.853    
## participantma92:session3  3.333e-02  1.799e-01   0.185    0.853    
## participantod94:session3 -1.000e-01  1.799e-01  -0.556    0.578    
## participantug93:session3         NA         NA      NA       NA    
## participantha94:session4         NA         NA      NA       NA    
## participantma92:session4  6.667e-02  1.799e-01   0.371    0.711    
## participantod94:session4  6.667e-02  1.799e-01   0.371    0.711    
## participantug93:session4         NA         NA      NA       NA    
## participantha94:session5         NA         NA      NA       NA    
## participantma92:session5  1.000e-01  1.799e-01   0.556    0.578    
## participantod94:session5         NA         NA      NA       NA    
## participantug93:session5         NA         NA      NA       NA    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4926 on 522 degrees of freedom
## Multiple R-squared:  0.01634,    Adjusted R-squared:  -0.0157 
## F-statistic:  0.51 on 17 and 522 DF,  p-value: 0.9486
sjp.int(fit = fit_corrRespSessionPart, type = "eff")

#correct response 
fit_corrRespSession<-lm(corrResp~session*kategory,data = data)
summary(fit_corrRespSession)
## 
## Call:
## lm(formula = corrResp ~ session * kategory, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.8500 -0.5667  0.3250  0.4000  0.6000 
## 
## Coefficients:
##                              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                 5.000e-01  6.894e-02   7.253 1.47e-12 ***
## session2                    1.000e-01  1.034e-01   0.967   0.3340    
## session3                    5.000e-02  1.034e-01   0.484   0.6289    
## session4                    6.667e-02  1.126e-01   0.592   0.5540    
## session5                   -1.000e-01  1.290e-01  -0.775   0.4385    
## kategoryFace                2.200e-01  9.749e-02   2.257   0.0244 *  
## kategoryLandscape           1.000e-01  9.749e-02   1.026   0.3055    
## session2:kategoryFace      -1.700e-01  1.462e-01  -1.162   0.2456    
## session3:kategoryFace      -1.450e-01  1.462e-01  -0.992   0.3219    
## session4:kategoryFace      -2.200e-01  1.592e-01  -1.382   0.1676    
## session5:kategoryFace       2.300e-01  1.824e-01   1.261   0.2079    
## session2:kategoryLandscape -7.500e-02  1.462e-01  -0.513   0.6083    
## session3:kategoryLandscape  2.500e-02  1.462e-01   0.171   0.8643    
## session4:kategoryLandscape -3.333e-02  1.592e-01  -0.209   0.8342    
## session5:kategoryLandscape  9.970e-16  1.824e-01   0.000   1.0000    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4875 on 525 degrees of freedom
## Multiple R-squared:  0.03118,    Adjusted R-squared:  0.005347 
## F-statistic: 1.207 on 14 and 525 DF,  p-value: 0.2659
sjp.lm(fit = fit_corrRespSession)

fit_corrRespSet<-lm(corrResp~kategory*inSet,data = data)
summary(fit_corrRespSet)
## 
## Call:
## lm(formula = corrResp ~ kategory * inSet, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.8889 -0.3444  0.1111  0.2222  0.7556 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)               0.82222    0.04484  18.335  < 2e-16 ***
## kategoryFace             -0.04444    0.06342  -0.701    0.484    
## kategoryLandscape        -0.47778    0.06342  -7.534 2.12e-13 ***
## inSet1                   -0.57778    0.06342  -9.111  < 2e-16 ***
## kategoryFace:inSet1       0.36667    0.08969   4.088 5.01e-05 ***
## kategoryLandscape:inSet1  1.12222    0.08969  12.513  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4254 on 534 degrees of freedom
## Multiple R-squared:  0.2495, Adjusted R-squared:  0.2425 
## F-statistic:  35.5 on 5 and 534 DF,  p-value: < 2.2e-16
sjp.int(fit = fit_corrRespSet, type = "eff")

fit_corrRespParticipant<-lm(corrResp~kategory*participant,data = data)
summary(fit_corrRespParticipant)
## 
## Call:
## lm(formula = corrResp ~ kategory * participant, data = data)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
##  -0.78  -0.54   0.34   0.38   0.50 
## 
## Coefficients:
##                                     Estimate Std. Error t value Pr(>|t|)
## (Intercept)                        5.000e-01  1.546e-01   3.235  0.00129
## kategoryFace                       2.000e-01  2.186e-01   0.915  0.36059
## kategoryLandscape                  1.000e-01  2.186e-01   0.458  0.64749
## participantha94                   -1.811e-16  1.785e-01   0.000  1.00000
## participantma92                    4.000e-02  1.693e-01   0.236  0.81332
## participantod94                    1.000e-01  1.728e-01   0.579  0.56302
## participantug93                    1.532e-15  1.693e-01   0.000  1.00000
## kategoryFace:participantha94      -6.667e-02  2.524e-01  -0.264  0.79177
## kategoryLandscape:participantha94  3.333e-02  2.524e-01   0.132  0.89498
## kategoryFace:participantma92      -1.200e-01  2.394e-01  -0.501  0.61645
## kategoryLandscape:participantma92 -3.139e-15  2.394e-01   0.000  1.00000
## kategoryFace:participantod94      -1.750e-01  2.444e-01  -0.716  0.47423
## kategoryLandscape:participantod94 -1.750e-01  2.444e-01  -0.716  0.47423
## kategoryFace:participantug93       8.000e-02  2.394e-01   0.334  0.73842
## kategoryLandscape:participantug93  6.000e-02  2.394e-01   0.251  0.80223
##                                     
## (Intercept)                       **
## kategoryFace                        
## kategoryLandscape                   
## participantha94                     
## participantma92                     
## participantod94                     
## participantug93                     
## kategoryFace:participantha94        
## kategoryLandscape:participantha94   
## kategoryFace:participantma92        
## kategoryLandscape:participantma92   
## kategoryFace:participantod94        
## kategoryLandscape:participantod94   
## kategoryFace:participantug93        
## kategoryLandscape:participantug93   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.4887 on 525 degrees of freedom
## Multiple R-squared:  0.02615,    Adjusted R-squared:  0.0001782 
## F-statistic: 1.007 on 14 and 525 DF,  p-value: 0.4446
sjp.int(fit = fit_corrRespParticipant, type = "eff")
## `sjp.int()` will become deprecated in the future. Please use `plot_model()` instead.

# reaction time
fit_rtResp<-lm(rtResp~kategory*inSet, data)
summary(fit_rtResp)
## 
## Call:
## lm(formula = rtResp ~ kategory * inSet, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.8753 -0.4474 -0.1997  0.1549  6.1917 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)               0.99808    0.08058  12.386   <2e-16 ***
## kategoryFace             -0.18165    0.11396  -1.594   0.1115    
## kategoryLandscape         0.02714    0.11396   0.238   0.8119    
## inSet1                    0.06191    0.11396   0.543   0.5872    
## kategoryFace:inSet1       0.01076    0.16117   0.067   0.9468    
## kategoryLandscape:inSet1 -0.40261    0.16117  -2.498   0.0128 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7645 on 534 degrees of freedom
## Multiple R-squared:  0.02899,    Adjusted R-squared:  0.0199 
## F-statistic: 3.189 on 5 and 534 DF,  p-value: 0.00758
sjp.int(fit = fit_rtResp,type = "eff")

fit_rtRespSession<-lm(rtResp~kategory*session, data)
summary(fit_rtRespSession)
## 
## Call:
## lm(formula = rtResp ~ kategory * session, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.2768 -0.3883 -0.1710  0.1836  5.6407 
## 
## Coefficients:
##                            Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                 1.61099    0.10218  15.766  < 2e-16 ***
## kategoryFace               -0.30035    0.14451  -2.078  0.03816 *  
## kategoryLandscape          -0.62994    0.14451  -4.359 1.57e-05 ***
## session2                   -0.66607    0.15327  -4.346 1.67e-05 ***
## session3                   -0.83591    0.15327  -5.454 7.61e-08 ***
## session4                   -0.96737    0.16686  -5.797 1.16e-08 ***
## session5                   -0.78261    0.19117  -4.094 4.91e-05 ***
## kategoryFace:session2       0.17388    0.21676   0.802  0.42281    
## kategoryLandscape:session2  0.57210    0.21676   2.639  0.00856 ** 
## kategoryFace:session3       0.08805    0.21676   0.406  0.68477    
## kategoryLandscape:session3  0.63104    0.21676   2.911  0.00375 ** 
## kategoryFace:session4       0.23571    0.23598   0.999  0.31832    
## kategoryLandscape:session4  0.64841    0.23598   2.748  0.00621 ** 
## kategoryFace:session5       0.23928    0.27035   0.885  0.37652    
## kategoryLandscape:session5  0.72305    0.27035   2.674  0.00772 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7225 on 525 degrees of freedom
## Multiple R-squared:  0.1472, Adjusted R-squared:  0.1245 
## F-statistic: 6.474 on 14 and 525 DF,  p-value: 4.012e-12
sjp.int(fit = fit_rtRespSession,type = "eff")

fit_rtRespParticipant<-lm(rtResp~kategory*participant, data)
summary(fit_rtRespParticipant)
## 
## Call:
## lm(formula = rtResp ~ kategory * participant, data = data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.2239 -0.3735 -0.1479  0.1973  4.1939 
## 
## Coefficients:
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                         3.0577     0.2096  14.592  < 2e-16 ***
## kategoryFace                       -0.8271     0.2964  -2.791 0.005449 ** 
## kategoryLandscape                  -1.3568     0.2964  -4.578 5.86e-06 ***
## participantha94                    -2.2891     0.2420  -9.460  < 2e-16 ***
## participantma92                    -2.3854     0.2296 -10.391  < 2e-16 ***
## participantod94                    -1.9848     0.2343  -8.472 2.44e-16 ***
## participantug93                    -1.9566     0.2296  -8.524  < 2e-16 ***
## kategoryFace:participantha94        0.7492     0.3422   2.189 0.029014 *  
## kategoryLandscape:participantha94   1.3393     0.3422   3.914 0.000103 ***
## kategoryFace:participantma92        0.7064     0.3246   2.176 0.029994 *  
## kategoryLandscape:participantma92   1.2838     0.3246   3.955 8.71e-05 ***
## kategoryFace:participantod94        0.6676     0.3313   2.015 0.044434 *  
## kategoryLandscape:participantod94   1.0916     0.3313   3.295 0.001052 ** 
## kategoryFace:participantug93        0.6529     0.3246   2.011 0.044830 *  
## kategoryLandscape:participantug93   1.2967     0.3246   3.994 7.41e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6627 on 525 degrees of freedom
## Multiple R-squared:  0.2827, Adjusted R-squared:  0.2636 
## F-statistic: 14.78 on 14 and 525 DF,  p-value: < 2.2e-16
sjp.int(fit = fit_rtRespParticipant,type = "eff")

if(T){

fitBrmCorrResp<-brm(corrResp~inSet*kategory+(1|session)+(1|participant)+(1|id),data = data,family = bernoulli())
summary(fitBrmCorrResp)
marginal_effects(fitBrmCorrResp)
plot(fitBrmCorrResp)

fitBrmRt<-brm(rtResp~inSet*kategory+(1|session)+(1|participant)+(1|id),data = data,family =exgaussian(link = "identity", link_sigma = "log", link_beta = "log"))
summary(fitBrmRt)
marginal_effects(fitBrmRt)
plot(fitBrmRt)

}
## Compiling the C++ model
## Start sampling

## Compiling the C++ model
## Start sampling